/**
 * \file Thread_Win32.cpp
 * \brief Thread declaration class
 * \author Edouard ROGE
 * \date 29 august 2012
 */

#include "Core/Log/LogManager.h"
#include "Core/Profile/CodeProfile.h"
#include "ThreadManager.h"
#include "Thread_Win32.h"

namespace Core
{
	namespace Thread
	{
		Thread::Thread() : m_thread(0), m_parentThread(0)
		{

		}

		Thread::~Thread()
		{
		}

		void Thread::Start()
		{
			ThreadManager::GetInstance().Register(this);
		}

		uint32 Thread::GetThreadId() const
		{
			return (uint32)GetCurrentThread();
		}

		DWORD WINAPI Thread::RunThread(void * _pContext)
		{
			Thread * pThread = (Thread*)_pContext;
			PROFILEEX("New thread", pThread->m_parentThread);
			pThread->m_thread = pThread->GetThreadId();
			LOG_INFO("Start thread %d", pThread->m_thread);
			pThread->Run();
			LOG_INFO("End thread %d", pThread->m_thread);
			ThreadManager::GetInstance().Unregister(pThread);
			return 0;
		}
	}
}
